package com.apache.bid.service.impl;

import java.util.List;

import com.apache.api.vo.ParamsVo;
import com.apache.bid.common.Constant;
import com.apache.bid.common.cache.BidCacheFactory;
import com.apache.bid.common.cache.BidCacheManager;
import com.apache.bid.common.vo.BidItemCacheVo;
import com.apache.bid.entity.BidItem;
import com.apache.bid.manager.BidItemManager;
import com.apache.cache.util.Validator;
import com.apache.database.db.IDao;
import com.apache.database.model.MethodParam;
import com.apache.database.model.Page;
import com.apache.exception.BusinessException;
import com.apache.tools.DateUtils;

public class BidItemManagerImpl implements BidItemManager {

	protected IDao bidItemDao;
	protected final String entityName = "com.apache.bid.entity.BidItem";

	public void setBidItemDao(IDao bidItemDao) {
		this.bidItemDao = bidItemDao;
	}

	public String saveInfo(ParamsVo<BidItem> vo) throws BusinessException {
		BidItem bidItem = vo.getObj();
		String infoId = Validator.generate();
		//定义对象缓存KEY,如果不需要缓存对象请不要对变量赋值，如果要缓存对象建议使用infoId
		String cacheKey = "";
		//String cacheKey="bidItem_"+infoId;
		if (Validator.isNull(bidItem.getItemId())) {
			bidItem.setItemId(infoId);
		}
		if (Constant.getInstance().ifWriteDatabase()) {
			bidItem.setCreateTime(DateUtils.Now.fmt_yyyyMMdd_HHmmss());
			bidItem = initBidItem(bidItem);
			MethodParam param = new MethodParam("BidItem", cacheKey, "", entityName);
			param.setVaule(bidItem);
			if (bidItemDao.insert(param)) {
				return bidItem.getItemId();
			}
		} else {
			///////////////需要处理缓存结果//////////////////
			return bidItem.getItemId();
		}
		return "";
	}

	private BidItem initBidItem(BidItem item) {
		item.setCurrency(Validator.getDefaultStr(item.getCurrency(), "CNY"));//币种：CNY=人民币、=美元
		item.setPriceUnit(Validator.getDefaultStr(item.getPriceUnit(), "元"));//货币单位：万元、元
		item.setSessionId(Validator.getDefaultStr(item.getSessionId(), "0"));
		item.setSessionType(Validator.getDefaultStr(item.getSessionType(), "3"));
		item.setGroupId(Validator.getDefaultStr(item.getGroupId(), "0"));
		item.setIfBidDyn(Validator.getDefaultStr(item.getIfBidDyn(), "T"));//是否动态报价（T/F）（缺省值T）
		item.setItemStatus(Validator.getDefaultStr(item.getItemStatus(), "0"));
		item.setItemNum(Validator.getDefaultStr(item.getItemNum(), "1"));
		item.setDecimalCount(Validator.getDefaultStr(item.getDecimalCount(), "2"));
		item.setAllowUpdateTimes(Validator.getDefaultStr(item.getAllowUpdateTimes(), "0"));
		item.setBidWay(Validator.getDefaultStr(item.getBidWay(), "1"));//竞价控制方式:1=事先设定竞价时间（缺省常用）、2=现场控制竞价时间、3=手工控制竞价时间
		item.setPriceFlag(Validator.getDefaultStr(item.getPriceFlag(), "0"));//价格类型（整体价格0、单位价格1）,默认0
		item.setBailPrice(Validator.getDefaultStr(item.getBailPrice(), "0"));//应交保证金金额（公示显示用）（缺省=0）（单项目固定保证金）
		item.setDelayControl(Validator.getDefaultStr(item.getDelayControl(), "F"));//是否延牌（T/F)缺省F
		item.setIfFee(Validator.getDefaultStr(item.getIfFee(), "F"));//是否收取佣金服务费(T/F)
		item.setAllowFirstValue(Validator.getDefaultStr(item.getAllowFirstValue(), "T"));//是否允许举牌，即是否允许以起始价出价（T/F),缺省T
		item.setAllowRepeat(Validator.getDefaultStr(item.getAllowRepeat(), "F"));//是否允许连续报价（T/F),缺省F
		item.setIfRight(Validator.getDefaultStr(item.getIfRight(), "F"));//是否允许过程行权（T/F)
		item.setAllowEndPrio(Validator.getDefaultStr(item.getAllowEndPrio(), "F"));//是否允许事后行权
		item.setAllowHallPrio(Validator.getDefaultStr(item.getAllowHallPrio(), "T"));//事后行权方式：场内（T），场外（F）
		item.setIsPreview(Validator.getDefaultStr(item.getIsPreview(), "F"));//是否预演(T/F)（缺省=F）
		item.setPackId(Validator.getDefaultStr(item.getPackId(), "0"));
		item.setProId(Validator.getDefaultStr(item.getProId(), "0"));
		item.setSysId(Validator.getDefaultStr(item.getSysId(), "0"));
		item.setFallDecrement(Validator.getDefaultStr(item.getFallDecrement(), "0"));//降价幅度（常用bidmode=5\6\7)（缺省=0）
		item.setFallLimitTime(Validator.getDefaultStr(item.getFallLimitTime(), "0"));//降价周期（常用bidmode=5\6\7)（缺省=0）
		item.setFallLowerstPrice(Validator.getDefaultStr(item.getFallLowerstPrice(), "0"));//降价底线（常用bidmode=5\6\7)（缺省=0）
		item.setNetBidKind(Validator.getDefaultStr(item.getNetBidKind(), "A"));
		item.setOrderNumber(Validator.getDefaultStr(item.getOrderNumber(), "65535"));
		item.setvFlag(Validator.getDefaultStr(item.getvFlag(), "F"));//是否启用V型竞价
		item.setDirection(Validator.getDefaultStr(item.getDirection(), "T"));//方向：默认正（T)、反（F）
		item.setOncevalue(Validator.getDefaultStr(item.getOncevalue(), "0"));//是否一口价。0不是一口价。
		item.setAllowAdd(Validator.getDefaultStr(item.getAllowAdd(), "F"));//是否允许最高报价人加价
		item.setAllowAddTime("0");//最高报价人加价时间
		return item;
	}

	public boolean editInfo(ParamsVo<BidItem> vo) throws BusinessException {
		String key = vo.getMethodKey();
		if (Validator.isNull(key)) {
			BidItem bidItem = vo.getObj();
			if (Validator.isNotNull(bidItem.getItemId())) {
				String cacheKey = "";
				//String cacheKey="bidItem_"+bidItem.getItemid();
				if (Constant.getInstance().ifWriteDatabase()) {
					bidItem.setModifyTime(DateUtils.Now.fmt_yyyyMMdd_HHmmss());
					MethodParam param = new MethodParam("BidItem", cacheKey, "", entityName);
					param.setVaule(bidItem);
					boolean mark = bidItemDao.edit(param);
					if (mark) {
						//param.setKey("ById");
						//param.setInfoId(bidItem.getItemId());
						//bidItem = (BidItem) bidItemDao.selectById(param);
						if (!Constant.getInstance().getItemConfig("statusTemp").equals(bidItem.getItemStatus())) {
							BidCacheManager cache = BidCacheFactory.getInstance().getCacheManager("item");
							BidItemCacheVo itemVo = (BidItemCacheVo) cache.getCacheObjectByKey(cache.item_prefix
									+ bidItem.getItemId());
							if (!Validator.isEmpty(itemVo)) {
								itemVo.addItemInfo(bidItem);
								cache.updateCacheObject(itemVo);
							}
						}
					}
					return mark;
				} else {
					///////////////需要处理缓存结果//////////////////
					vo.setParams("methodCode", "editItem");
					return true;
				}
			}
		} else {
			MethodParam param = new MethodParam(key, "", "", entityName);
			if ("BidItemStatus".equals(key)) {
				param.setParams(vo.getParams());
				return bidItemDao.edit(param);
			}
		}
		return false;
	}

	@SuppressWarnings("rawtypes")
	public boolean deleteInfo(ParamsVo<BidItem> vo) throws BusinessException {
		String infoId = vo.getInfoId();
		if (Validator.isNull(infoId)) {
			String seId = String.valueOf(vo.getParams("sessionId"));
			if (Validator.isNull(seId))
				return false;
			if (Constant.getInstance().ifWriteDatabase()) {
				MethodParam param = new MethodParam("BySessionId", "", "", entityName);
				param.setParams("sessionId", seId);
				param.setDelete(true);
				return bidItemDao.delete(param);
			} else {
				vo.setParams("methodCode", "delItem");
				return true;
			}
		}
		String cacheKey = "";
		//String cacheKey="bidItem_"+infoId;
		String mark = Validator.getDefaultStr(String.valueOf(vo.getParams("isDelete")), "true");
		if (Constant.getInstance().ifWriteDatabase()) {
			MethodParam param = new MethodParam("ById", cacheKey, "", entityName);
			boolean flag = false;
			if ("false".equals(mark)) {//逻辑删除
				param.setInfoId(infoId);
				BidItem info = (BidItem) bidItemDao.selectById(param);
				if (Validator.isEmpty(info)) {
					return false;
				}
				param.setVaule(info);//此处需要先将状态值赋值为删除状态
				param.setKey("BidItem");
				flag = bidItemDao.edit(param);
			} else {
				param.setParams("itemId", infoId);
				param.setDelete(true);
				flag = bidItemDao.delete(param);
			}
			if (flag) {
				BidCacheManager cache = BidCacheFactory.getInstance().getCacheManager("item");
				cache.removeCacheObject(BidCacheManager.item_prefix + infoId);
			}
			return flag;
		} else {
			///////////////需要处理缓存结果//////////////////
			if ("false".equals(mark)) {//逻辑删除
			} else {
			}
			vo.setParams("methodCode", "delItem");
			return true;
		}
	}

	public Object getInfoById(ParamsVo<BidItem> vo) {
		String infoId = vo.getInfoId();
		String cacheKey = "";
		//String cacheKey="bidItem_"+infoId;
		if (Validator.isNull(infoId)) {
			return null;
		}
		String key = Validator.getDefaultStr(vo.getMethodKey(), "ById");
		MethodParam param = new MethodParam(key, cacheKey, "", entityName);
		param.setInfoId(infoId);
		return bidItemDao.selectById(param);
	}

	public Object execute(ParamsVo<BidItem> vo) {
		String key = vo.getKey();
		if ("itemNum".equals(key)) {
			if (Validator.isNull(vo.getInfoId()))
				return null;
			return getItemNumBySessionId(vo.getInfoId());
		} else if ("nextItemBySeId".equalsIgnoreCase(key)) {
			return getNextItemBySeId(vo.getObj());
		}

		return null;
	}

	private Object getNextItemBySeId(BidItem item) {
		MethodParam param = new MethodParam("NextItemBySeId", "", "", entityName);
		param.setParams("sessionId", item.getSessionId());
		param.setParams("orderNumber", item.getOrderNumber());
		param.setParams("itemStatus", Constant.getInstance().getItemConfig("statusPubslish"));
		return bidItemDao.selectSingle(param);
	}

	/**
	 * description:  获取指定session中的标数量级量大排序号
	 * @param sessionId（countNum，orderNumber）
	 */
	private Object getItemNumBySessionId(String sessionId) {
		MethodParam param = new MethodParam("ItemNumBySessionId", "", "", entityName);
		param.setParams("sessionId", sessionId);
		return bidItemDao.selectSingle(param);
	}

	public Page getPageInfo(ParamsVo<BidItem> vo) {
		MethodParam param = setMethodParams(vo, 2);
		int pageSize = Integer.valueOf(Validator.getDefaultStr(String.valueOf(vo.getParams("pageSize")), "10"));
		int pageIndex = Integer.valueOf(Validator.getDefaultStr(String.valueOf(vo.getParams("pageIndex")), "1"));
		param.setPageIndex(pageIndex);
		param.setPageSize(pageSize);
		//param.setOrderby(" order_number asc,create_time desc");
		String orderBy = Validator.getDefaultStr(String.valueOf(vo.getParams("orderBy")),
				" order by abs(order_number) asc,create_time desc ");
		param.setParams("orderBy", orderBy);
		Page page = bidItemDao.pageSelect(param);
		return page;
	}

	public List<BidItem> getList(ParamsVo<BidItem> vo) {
		MethodParam param = setMethodParams(vo, 2);
		//param.setOrderby(" order_number asc,create_time desc");
		String orderBy = Validator.getDefaultStr(String.valueOf(vo.getParams("orderBy")),
				" order by abs(order_number) asc,create_time desc ");
		param.setParams("orderBy", orderBy);
		return bidItemDao.select(param);
	}

	public long countInfo(ParamsVo<BidItem> vo) {
		MethodParam param = setMethodParams(vo, 1);
		return bidItemDao.count(param);
	}

	private MethodParam setMethodParams(ParamsVo<BidItem> vo, int type) {
		String methodKey = Validator.getDefaultStr(vo.getMethodKey(), "ByProperty");
		StringBuffer sb = new StringBuffer(bidItemDao.getSql(type));
		MethodParam param = new MethodParam(methodKey, "", "", entityName);
		BidItem bidItem = vo.getObj();
		param.setResultCache(false);

		if (Validator.isNotNull(String.valueOf(vo.getParams("currentTimePre")))
				&& Validator.isNotNull(bidItem.getSessionId())) {
			param.setParams("openTimePre",
					" and (item_status = '0' or open_time_pre > '" + String.valueOf(vo.getParams("currentTimePre"))
							+ "')");
			param.setParams("sessionId", bidItem.getSessionId());
			//return param;
		}
		if (!Validator.isEmpty(bidItem)) {
			if (Validator.isNotNull(bidItem.getItemId())) {
				sb.append(" and itemId = :itemId");
				param.setParams("itemId", bidItem.getItemId());
			}
			if (Validator.isNotNull(bidItem.getSessionId())) {
				sb.append(" and sessionId = :sessionId");
				param.setParams("sessionId", bidItem.getSessionId());
			}
			if (Validator.isNotNull(bidItem.getSessionType())) {
				sb.append(" and sessionType = :sessionType");
				param.setParams("sessionType", bidItem.getSessionType());
			}
			if (Validator.isNotNull(bidItem.getSessionName())) {
				sb.append(" and sessionName = :sessionName");
				param.setParams("sessionName", bidItem.getSessionName());
			}
			if (Validator.isNotNull(bidItem.getGroupId())) {
				sb.append(" and groupId = :groupId");
				param.setParams("groupId", bidItem.getGroupId());
			}
			if (Validator.isNotNull(bidItem.getGroupName())) {
				sb.append(" and groupName = :groupName");
				param.setParams("groupName", bidItem.getGroupName());
			}
			if (Validator.isNotNull(bidItem.getBidMode())) {
				sb.append(" and bidMode = :bidMode");
				param.setParams("bidMode", bidItem.getBidMode());
			}
			if (Validator.isNotNull(bidItem.getIfBidDyn())) {
				sb.append(" and ifBidDyn = :ifBidDyn");
				param.setParams("ifBidDyn", bidItem.getIfBidDyn());
			}
			if (Validator.isNotNull(bidItem.getItemNo())) {
				sb.append(" and itemNo = :itemNo");
				param.setParams("itemNo", bidItem.getItemNo());
			}
			if (Validator.isNotNull(bidItem.getItemName())) {
				sb.append(" and itemName like '%" + bidItem.getItemName() + "%' ");
				param.setParams("itemName", " like '%" + bidItem.getItemName() + "%' ");
			}
			if (Validator.isNotNull(bidItem.getItemType())) {
				sb.append(" and itemType = :itemType");
				param.setParams("itemType", bidItem.getItemType());
			}
			if (Validator.isNotNull(bidItem.getItemTypeName())) {
				sb.append(" and itemTypeName = :itemTypeName");
				param.setParams("itemTypeName", bidItem.getItemTypeName());
			}
			if (Validator.isNotNull(bidItem.getItemSubname())) {
				sb.append(" and itemSubname = :itemSubname");
				param.setParams("itemSubname", bidItem.getItemSubname());
			}
			if (Validator.isNotNull(bidItem.getItemStatus())) {
				sb.append(" and itemStatus = :itemStatus");
				param.setParams("itemStatus", bidItem.getItemStatus());
			}
			if (Validator.isNotNull(bidItem.getItemNum())) {
				sb.append(" and itemNum = :itemNum");
				param.setParams("itemNum", bidItem.getItemNum());
			}
			if (Validator.isNotNull(bidItem.getItemNumDesc())) {
				sb.append(" and itemNumDesc = :itemNumDesc");
				param.setParams("itemNumDesc", bidItem.getItemNumDesc());
			}
			if (Validator.isNotNull(bidItem.getItemUnitName())) {
				sb.append(" and itemUnitName = :itemUnitName");
				param.setParams("itemUnitName", bidItem.getItemUnitName());
			}
			if (Validator.isNotNull(bidItem.getIncrementGroup())) {
				sb.append(" and incrementGroup = :incrementGroup");
				param.setParams("incrementGroup", bidItem.getIncrementGroup());
			}
			if (Validator.isNotNull(bidItem.getIncrementValue())) {
				sb.append(" and incrementValue = :incrementValue");
				param.setParams("incrementValue", bidItem.getIncrementValue());
			}
			if (Validator.isNotNull(bidItem.getFirstValuePre())) {
				sb.append(" and firstValuePre = :firstValuePre");
				param.setParams("firstValuePre", bidItem.getFirstValuePre());
			}
			if (Validator.isNotNull(bidItem.getOncevalue())) {
				sb.append(" and oncevalue = :oncevalue");
				param.setParams("oncevalue", bidItem.getOncevalue());
			}
			if (Validator.isNotNull(bidItem.getHoldvalue())) {
				sb.append(" and holdvalue = :holdvalue");
				param.setParams("holdvalue", bidItem.getHoldvalue());
			}
			if (Validator.isNotNull(bidItem.getHoldNoticeTime())) {
				sb.append(" and holdNoticeTime = :holdNoticeTime");
				param.setParams("holdNoticeTime", bidItem.getHoldNoticeTime());
			}
			if (Validator.isNotNull(bidItem.getDecimalCount())) {
				sb.append(" and decimalCount = :decimalCount");
				param.setParams("decimalCount", bidItem.getDecimalCount());
			}
			if (Validator.isNotNull(bidItem.getCurrency())) {
				sb.append(" and currency = :currency");
				param.setParams("currency", bidItem.getCurrency());
			}
			if (Validator.isNotNull(bidItem.getPriceUnit())) {
				sb.append(" and priceUnit = :priceUnit");
				param.setParams("priceUnit", bidItem.getPriceUnit());
			}
			if (Validator.isNotNull(bidItem.getAllowUpdateTimes())) {
				sb.append(" and allowUpdateTimes = :allowUpdateTimes");
				param.setParams("allowUpdateTimes", bidItem.getAllowUpdateTimes());
			}
			if (Validator.isNotNull(bidItem.getBidWay())) {
				sb.append(" and bidWay = :bidWay");
				param.setParams("bidWay", bidItem.getBidWay());
			}
			if (Validator.isNotNull(bidItem.getPriceFlag())) {
				sb.append(" and priceFlag = :priceFlag");
				param.setParams("priceFlag", bidItem.getPriceFlag());
			}
			if (Validator.isNotNull(bidItem.getFlagTime())) {
				sb.append(" and flagTime = :flagTime");
				param.setParams("flagTime", bidItem.getFlagTime());
			}
			if (Validator.isNotNull(bidItem.getBailPrice())) {
				sb.append(" and bailPrice = :bailPrice");
				param.setParams("bailPrice", bidItem.getBailPrice());
			}
			if (Validator.isNotNull(bidItem.getCreateTime())) {
				sb.append(" and createTime = :createTime");
				param.setParams("createTime", bidItem.getCreateTime());
			}
			if (Validator.isNotNull(bidItem.getAuditTime())) {
				sb.append(" and auditTime = :auditTime");
				param.setParams("auditTime", bidItem.getAuditTime());
			}
			if (Validator.isNotNull(bidItem.getOpenTimePre())) {
				sb.append(" and openTimePre = :openTimePre");
				param.setParams("openTimePre", " and open_time_pre = " + bidItem.getOpenTimePre());
			}
			if (Validator.isNotNull(bidItem.getFirstBidTimePre())) {
				sb.append(" and firstBidTimePre = :firstBidTimePre");
				param.setParams("firstBidTimePre", bidItem.getFirstBidTimePre());
			}
			if (Validator.isNotNull(bidItem.getCloseTimePre())) {
				sb.append(" and closeTimePre = :closeTimePre");
				param.setParams("closeTimePre", bidItem.getCloseTimePre());
			}
			if (Validator.isNotNull(bidItem.getLimitTime())) {
				sb.append(" and limitTime = :limitTime");
				param.setParams("limitTime", bidItem.getLimitTime());
			}
			if (Validator.isNotNull(bidItem.getDelayControl())) {
				sb.append(" and delayControl = :delayControl");
				param.setParams("delayControl", bidItem.getDelayControl());
			}
			if (Validator.isNotNull(bidItem.getDelayUnit())) {
				sb.append(" and delayUnit = :delayUnit");
				param.setParams("delayUnit", bidItem.getDelayUnit());
			}
			if (Validator.isNotNull(bidItem.getDelayPeriod())) {
				sb.append(" and delayPeriod = :delayPeriod");
				param.setParams("delayPeriod", bidItem.getDelayPeriod());
			}
			if (Validator.isNotNull(bidItem.getDelayDeadTime())) {
				sb.append(" and delayDeadTime = :delayDeadTime");
				param.setParams("delayDeadTime", bidItem.getDelayDeadTime());
			}
			if (Validator.isNotNull(bidItem.getDelayPeriodMax())) {
				sb.append(" and delayPeriodMax = :delayPeriodMax");
				param.setParams("delayPeriodMax", bidItem.getDelayPeriodMax());
			}
			if (Validator.isNotNull(bidItem.getIfFee())) {
				sb.append(" and ifFee = :ifFee");
				param.setParams("ifFee", bidItem.getIfFee());
			}
			if (Validator.isNotNull(bidItem.getAllowFirstValue())) {
				sb.append(" and allowFirstValue = :allowFirstValue");
				param.setParams("allowFirstValue", bidItem.getAllowFirstValue());
			}
			if (Validator.isNotNull(bidItem.getAllowRepeat())) {
				sb.append(" and allowRepeat = :allowRepeat");
				param.setParams("allowRepeat", bidItem.getAllowRepeat());
			}
			if (Validator.isNotNull(bidItem.getAllowEndPrio())) {
				sb.append(" and allowEndPrio = :allowEndPrio");
				param.setParams("allowEndPrio", bidItem.getAllowEndPrio());
			}
			if (Validator.isNotNull(bidItem.getAllowHallPrio())) {
				sb.append(" and allowHallPrio = :allowHallPrio");
				param.setParams("allowHallPrio", bidItem.getAllowHallPrio());
			}
			if (Validator.isNotNull(bidItem.getAllowPrioTime())) {
				sb.append(" and allowPrioTime = :allowPrioTime");
				param.setParams("allowPrioTime", bidItem.getAllowPrioTime());
			}
			if (Validator.isNotNull(bidItem.getAllowAdd())) {
				sb.append(" and allowAdd = :allowAdd");
				param.setParams("allowAdd", bidItem.getAllowAdd());
			}
			if (Validator.isNotNull(bidItem.getAllowAddTime())) {
				sb.append(" and allowAddTime = :allowAddTime");
				param.setParams("allowAddTime", bidItem.getAllowAddTime());
			}
			if (Validator.isNotNull(bidItem.getPrioControl())) {
				sb.append(" and prioControl = :prioControl");
				param.setParams("prioControl", bidItem.getPrioControl());
			}
			if (Validator.isNotNull(bidItem.getEndPrioDays())) {
				sb.append(" and endPrioDays = :endPrioDays");
				param.setParams("endPrioDays", bidItem.getEndPrioDays());
			}
			if (Validator.isNotNull(bidItem.getBidInterval())) {
				sb.append(" and bidInterval = :bidInterval");
				param.setParams("bidInterval", bidItem.getBidInterval());
			}
			if (Validator.isNotNull(bidItem.getBidIntervalLimit())) {
				sb.append(" and bidIntervalLimit = :bidIntervalLimit");
				param.setParams("bidIntervalLimit", bidItem.getBidIntervalLimit());
			}
			if (Validator.isNotNull(bidItem.getIsPreview())) {
				sb.append(" and isPreview = :isPreview");
				param.setParams("isPreview", bidItem.getIsPreview());
			}
			if (Validator.isNotNull(bidItem.getItemSource())) {
				sb.append(" and itemSource = :itemSource");
				param.setParams("itemSource", bidItem.getItemSource());
			}
			if (Validator.isNotNull(bidItem.getItemBrand())) {
				sb.append(" and itemBrand = :itemBrand");
				param.setParams("itemBrand", bidItem.getItemBrand());
			}
			if (Validator.isNotNull(bidItem.getItemArea())) {
				sb.append(" and itemArea = :itemArea");
				param.setParams("itemArea", bidItem.getItemArea());
			}
			if (Validator.isNotNull(bidItem.getPackId())) {
				sb.append(" and packId = :packId");
				param.setParams("packId", bidItem.getPackId());
			}
			if (Validator.isNotNull(bidItem.getProId())) {
				sb.append(" and proId = :proId");
				param.setParams("proId", bidItem.getProId());
			}
			if (Validator.isNotNull(bidItem.getSysId())) {
				sb.append(" and sysId = :sysId");
				param.setParams("sysId", bidItem.getSysId());
			}
			if (Validator.isNotNull(bidItem.getPicUrl())) {
				sb.append(" and picUrl = :picUrl");
				param.setParams("picUrl", bidItem.getPicUrl());
			}
			if (Validator.isNotNull(bidItem.getPicUrlSmall())) {
				sb.append(" and picUrlSmall = :picUrlSmall");
				param.setParams("picUrlSmall", bidItem.getPicUrlSmall());
			}
			if (Validator.isNotNull(bidItem.getOrgEname())) {
				sb.append(" and orgEname = :orgEname");
				param.setParams("orgEname", bidItem.getOrgEname());
			}
			if (Validator.isNotNull(bidItem.getOrgCname())) {
				sb.append(" and orgCname = :orgCname");
				param.setParams("orgCname", bidItem.getOrgCname());
			}
			if (Validator.isNotNull(bidItem.getFallDecrement())) {
				sb.append(" and fallDecrement = :fallDecrement");
				param.setParams("fallDecrement", bidItem.getFallDecrement());
			}
			if (Validator.isNotNull(bidItem.getFallLimitTime())) {
				sb.append(" and fallLimitTime = :fallLimitTime");
				param.setParams("fallLimitTime", bidItem.getFallLimitTime());
			}
			if (Validator.isNotNull(bidItem.getFallLowerstPrice())) {
				sb.append(" and fallLowerstPrice = :fallLowerstPrice");
				param.setParams("fallLowerstPrice", bidItem.getFallLowerstPrice());
			}
			if (Validator.isNotNull(bidItem.getModifyTime())) {
				sb.append(" and modifyTime = :modifyTime");
				param.setParams("modifyTime", bidItem.getModifyTime());
			}
			if (Validator.isNotNull(bidItem.getNetBidKind())) {
				sb.append(" and netBidKind = :netBidKind");
				param.setParams("netBidKind", bidItem.getNetBidKind());
			}
			if (Validator.isNotNull(bidItem.getOrderNumber())) {
				sb.append(" and orderNumber = :orderNumber");
				param.setParams("orderNumber", bidItem.getOrderNumber());
			}
			if (Validator.isNotNull(bidItem.getSpare1())) {
				sb.append(" and spare1 = :spare1");
				param.setParams("spare1", bidItem.getSpare1());
			}
			if (Validator.isNotNull(bidItem.getSpare2())) {
				sb.append(" and spare2 = :spare2");
				param.setParams("spare2", bidItem.getSpare2());
			}
			if (Validator.isNotNull(bidItem.getSpare3())) {
				sb.append(" and spare3 = :spare3");
				param.setParams("spare3", bidItem.getSpare3());
			}
			if (Validator.isNotNull(bidItem.getSpare4())) {
				sb.append(" and spare4 = :spare4");
				param.setParams("spare4", bidItem.getSpare4());
			}
			if (Validator.isNotNull(bidItem.getSpare5())) {
				sb.append(" and spare5 = :spare5");
				param.setParams("spare5", bidItem.getSpare5());
			}
			if (Validator.isNotNull(bidItem.getIfRight())) {
				sb.append(" and ifRight = :ifRight");
				param.setParams("ifRight", bidItem.getIfRight());
			}
			if (Validator.isNotNull(bidItem.getvFlag())) {
				sb.append(" and vflag = :vflag");
				param.setParams("vflag", bidItem.getvFlag());
			}
			if (Validator.isNotNull(bidItem.getDirection())) {
				sb.append(" and direction = :direction");
				param.setParams("direction", bidItem.getDirection());
			}
		}
		param.setSqlStr(sb.toString());
		return param;
	}
}
